package com.ld.poetry.aigc.iflycode.gclu.unittest;



import com.ld.poetry.aigc.iflycode.gclu.service.IPhoneVerificationCodeService;
import com.ld.poetry.aigc.iflycode.gclu.service.impl.PhoneVerificationCodeServiceImpl;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;

public class PhoneVerificationCodeServiceImplTest {

    private IPhoneVerificationCodeService phoneVerificationCodeService;

    @Before
    public void setUp() {
        phoneVerificationCodeService = new PhoneVerificationCodeServiceImpl();
    }

    @Test
    public void testSave() {
        String telephone = "13800138000";
        boolean result = phoneVerificationCodeService.save(telephone);
        assertTrue(result);
    }

    @Test(expected = IncorrectCodeRuntimteException.class)
    public void testCheckIncorrectCode() {
        String telephone = "13800138000";
        String code = "123456";
        phoneVerificationCodeService.check(telephone, code);
    }

    @Test(expected = ExpireCodeRuntimeException.class)
    public void testCheckExpiredCode() {
        String telephone = "13800138000";
        String code = "123456";
        PhoneVerificationCode verificationCode = new PhoneVerificationCode();
        verificationCode.setPhone(telephone);
        verificationCode.setVerificationCode(code);
        verificationCode.setCreateTime(new Date());
        verificationCode.setIsCheck(false);
        verificationCode.setCheckTimes(0);
        phoneVerificationCodeService.getBaseMapper().insert(verificationCode);
        phoneVerificationCodeService.check(telephone, code);
    }
}
